import { prop, Ref } from '@typegoose/typegoose'
import { ApiModelProperty } from '@nestjs/swagger'
import { IsUrl, IsNotEmpty } from 'class-validator'
import { Attribute } from './attribute.model'
import { AttributeTyps } from '../../../../apps/admin/src/categories/AttributeTyps.enum'
import { StringOrObject } from '../../../../apps/admin/src/categories/StringOrObject.enum'

export class Category {
  @ApiModelProperty({ description: `所属分类(父类) 可为空字符串, 或者 Object.id`, type: String, example: 'Object._id', required: false })
  @prop({ ref: Category })
  parent?: Ref<Category>

  @ApiModelProperty({ description: '分类名称', example: '上衣' })
  @prop()
  @IsNotEmpty({ message: '请输入分类名称' })
  name !: string

  @ApiModelProperty({ description: '分类图标', example: 'https://shubuzuo.top/img/logo.jpg', required: false })
  @prop()
  @IsUrl()
  url?: string

  @ApiModelProperty({
    description: '属性设定', example: [{
      name: '尺码',
      type: AttributeTyps.selects,
      messageType: StringOrObject.array,
      message: ['S', 'M', 'L', 'XL']
    },
    {
      name: '衣长',
      type: AttributeTyps.select,
      messageType: StringOrObject.number,
      message: 156
    }, {
      name: '号型',
      type: AttributeTyps.input,
      messageType: StringOrObject.string,
      message: '175/92A'
    }],
    required: false,
    type: [Attribute]
  })
  @prop()
  attributes?: Attribute[]
}